package com.nineclock.sign.listener;


import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.nineclock.sign.excel.SignExcelMember;
import com.nineclock.sign.service.SignService;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * 解析员工excel监听器
 */
@Slf4j
public class SignExcelMemberListener extends AnalysisEventListener<SignExcelMember> {

    private List<SignExcelMember> memberList = new ArrayList<>();
    private SignService signService;
    private Long companyId;

    public SignExcelMemberListener(SignService signService,Long companyId) {
        this.signService = signService;
        this.companyId = companyId;
    }


    @Override
    public void invoke(SignExcelMember signExcelMember, AnalysisContext analysisContext) {
        memberList.add(signExcelMember);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        log.info("解析员工excel完毕，员工数据 = " + memberList);
        signService.handleParsedData(memberList,companyId);
    }
}